# Copyright (c) 2019 Presto Labs Pte. Ltd.
# Author: jaewon

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

def nazel_http_archive(name, **kwargs):
    existing_rule_keys = native.existing_rules().keys()
    if name in existing_rule_keys:
        return
    http_archive(name = name, **kwargs)

def nazel_dependencies():
    http_archive(
        name = "bazel_skylib",
        sha256 = "bbccf674aa441c266df9894182d80de104cabd19be98be002f6d478aaa31574d",
        strip_prefix = "bazel-skylib-2169ae1c374aab4a09aa90e65efe1a3aad4e279b",
        urls = [
            "https://nexus-repo.corp.prestolabs.io/repository/github-proxy/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz",
            "https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz",
        ],
    )

    http_archive(
        name = "rules_python",
        sha256 = "e5470e92a18aa51830db99a4d9c492cc613761d5bdb7131c04bd92b9834380f6",
        strip_prefix = "rules_python-4b84ad270387a7c439ebdccfd530e2339601ef27",
        urls = [
            "https://nexus-repo.corp.prestolabs.io/repository/github-proxy/bazelbuild/rules_python/archive/4b84ad270387a7c439ebdccfd530e2339601ef27.tar.gz",
            "https://github.com/bazelbuild/rules_python/archive/4b84ad270387a7c439ebdccfd530e2339601ef27.tar.gz",
        ],
    )

    http_archive(
        name = "rules_cc",
        sha256 = "29daf0159f0cf552fcff60b49d8bcd4f08f08506d2da6e41b07058ec50cfeaec",
        strip_prefix = "rules_cc-b7fe9697c0c76ab2fd431a891dbb9a6a32ed7c3e",
        urls = [
            "https://nexus-repo.corp.prestolabs.io/repository/github-proxy/bazelbuild/rules_cc/archive/b7fe9697c0c76ab2fd431a891dbb9a6a32ed7c3e.tar.gz",
            "https://github.com/bazelbuild/rules_cc/archive/b7fe9697c0c76ab2fd431a891dbb9a6a32ed7c3e.tar.gz",
        ],
    )

    # Google double conversion library
    # Imported using bazel since conda double-conversion package is outdated.
    nazel_http_archive(
        name = "com_github_google_double_conversion",
        urls = [
            "https://nexus-repo.corp.prestolabs.io/repository/github-proxy/google/double-conversion/archive/v3.0.3.tar.gz",
            "https://github.com/google/double-conversion/archive/v3.0.3.tar.gz",
        ],
        sha256 = "ac84e00c19fdb5ee20c01feb18b0fa2e938bf4b8cf71d43bab62502c8b65420a",
        strip_prefix = "double-conversion-3.0.3",
        build_file = "@coin//cc/third_party:double-conversion.BUILD",
    )

    # Google Benchmark
    nazel_http_archive(
        name = "com_github_google_benchmark",
        urls = [
            "https://nexus-repo.corp.prestolabs.io/repository/github-proxy/google/benchmark/archive/v1.4.1.tar.gz",
            "https://github.com/google/benchmark/archive/v1.4.1.tar.gz",
        ],
        sha256 = "f8e525db3c42efc9c7f3bc5176a8fa893a9a9920bbd08cef30fb56a51854d60d",
        strip_prefix = "benchmark-1.4.1",
    )

    # Google Abseil
    nazel_http_archive(
        name = "com_google_absl",
        urls = [
            "https://nexus-repo.corp.prestolabs.io/repository/github-proxy/abseil/abseil-cpp/archive/20220623.0.tar.gz",
            "https://github.com/abseil/abseil-cpp/archive/refs/tags/20220623.0.tar.gz",
        ],
        sha256 = "4208129b49006089ba1d6710845a45e31c59b0ab6bff9e5788a87f55c5abd602",
        strip_prefix = "abseil-cpp-20220623.0",
    )

    # JSON for Modern C++
    nazel_http_archive(
        name = "json_nlohmann_github_com",
        urls = [
            "https://nexus-repo.corp.prestolabs.io/repository/github-proxy/nlohmann/json/releases/download/v3.6.1/include.zip",
            "https://github.com/nlohmann/json/releases/download/v3.6.1/include.zip",
        ],
        strip_prefix = "include",
        sha256 = "69cc88207ce91347ea530b227ff0776db82dcb8de6704e1a3d74f4841bc651cf",
        build_file = "@coin//cc/third_party:nlohmann_json.BUILD",
    )

    # QuantStack xtl
    nazel_http_archive(
        name = "xtl_quantstack_github_com",
        urls = [
            "https://nexus-repo.corp.prestolabs.io/repository/github-proxy/QuantStack/xtl/archive/0.6.4.tar.gz",
            "https://github.com/QuantStack/xtl/archive/0.6.4.tar.gz",
        ],
        strip_prefix = "xtl-0.6.4",
        sha256 = "5db5087c37daab3e1d35337782f79972aaaf19218a0de786a0515f247244e390",
        build_file = "@coin//cc/third_party:xtl.BUILD",
    )

    # QuantStack xtensor
    nazel_http_archive(
        name = "xtensor_quantstack_github_com",
        urls = [
            "https://nexus-repo.corp.prestolabs.io/repository/github-proxy/QuantStack/xtensor/archive/0.20.7.tar.gz",
            "https://github.com/QuantStack/xtensor/archive/0.20.7.tar.gz",
        ],
        strip_prefix = "xtensor-0.20.7",
        sha256 = "b45290d1bb0d6cef44771e7482f1553b2aa54dbf99ef9406fec3eb1e4d01d52b",
        patches = ["@coin//cc/third_party:xtensor-0.20.7.patch"],
        build_file = "@coin//cc/third_party:xtensor.BUILD",
    )

    # QuantStack xtensor-python
    nazel_http_archive(
        name = "xtensor_python_quantstack_github_com",
        urls = [
            "https://nexus-repo.corp.prestolabs.io/repository/github-proxy/QuantStack/xtensor-python/archive/0.23.1.tar.gz",
            "https://github.com/QuantStack/xtensor-python/archive/0.23.1.tar.gz",
        ],
        strip_prefix = "xtensor-python-0.23.1",
        sha256 = "450b25f5c739df174b2a50774b89e68b23535fdc37cb55bd542ffdb7c78991ab",
        build_file = "@coin//cc/third_party:xtensor-python.BUILD",
    )

    # Msgpack-c
    nazel_http_archive(
        name = "msgpack_c_github_com",
        urls = [
            "https://nexus-repo.corp.prestolabs.io/repository/github-proxy/msgpack/msgpack-c/archive/cpp-3.2.1.zip",
            "https://github.com/msgpack/msgpack-c/archive/cpp-3.2.1.zip",
        ],
        strip_prefix = "msgpack-c-cpp-3.2.1",
        build_file = "@coin//cc/third_party:msgpack-c.BUILD",
    )

    # Toml11
    nazel_http_archive(
        name = "toml11_toruninja_github_com",
        urls = [
            "https://nexus-repo.corp.prestolabs.io/repository/github-proxy/ToruNiina/toml11/archive/v3.4.0.tar.gz",
            "https://github.com/ToruNiina/toml11/archive/v3.4.0.tar.gz",
        ],
        strip_prefix = "toml11-3.4.0",
        sha256 = "bc6d733efd9216af8c119d8ac64a805578c79cc82b813e4d1d880ca128bd154d",
        build_file = "@coin//cc/third_party:toml11.BUILD",
    )

    http_archive(
        name = "vitro_github_com",
        strip_prefix = "vitro-30dda58118295d4ae0c0d2470723b8256ed94350",
        urls = [
            "https://nexus-repo.corp.prestolabs.io/repository/github-proxy/elbaro/vitro/archive/30dda58118295d4ae0c0d2470723b8256ed94350.zip",
            "https://github.com/elbaro/vitro/archive/30dda58118295d4ae0c0d2470723b8256ed94350.zip",
        ],
        patch_args = ["-p1"],
        patches = ["@coin//cc/third_party:vitro.patch"],
        build_file_content = """
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")

package(default_visibility = ["//visibility:public"])

cc_library(
    name = "vitro",
    srcs = ["vitro.cc"],
    hdrs = ["vitro.h"],
    # srcs = glob(["**/*.cc"]),
    # hdrs = glob(["**/*.h"]),
    copts = [
        "-std=c++17",
    ],
    linkopts = [
        "-lpython3.10",
    ]
)
    """
    )

    # BlueBrain HighFive
    nazel_http_archive(
        name = "highfive_bluebrain_github_com",
        url = "https://github.com/BlueBrain/HighFive/archive/v2.2.1.tar.gz",
        strip_prefix = "HighFive-2.2.1",
        sha256 = "964c722ba916259209083564405ef9ce073b15e9412955fef9281576ea9c5b85",
        build_file = "@coin//cc/third_party:highfive.BUILD",
    )

    nazel_http_archive(
        name = "azmq_zeromq_github_com",
        url = "https://github.com/cqjjjzr/azmq/archive/d50063703bdcef068df889b02bfa9cf0238ef88a.zip",  # a temporary fork to use latest boost / zmq
        # url = "https://github.com/zeromq/azmq/archive/v1.0.2.tar.gz",
        strip_prefix = "azmq-d50063703bdcef068df889b02bfa9cf0238ef88a",
        sha256 = "6c84f975f3fc25d7d092fe71ad1734a0d6c5a23d20575be1188e1b88056daad2",
        build_file = "@coin//cc/third_party:azmq.BUILD",
    )
